<?php
namespace Components\User\Sha;

class Validation extends \Phalcon\Validation {
  public function checkStatus($status) {
    switch($status) {
      case '0':
        return ['code' => 0, 'msg' => '账号' . Constants::getByIndex('user_status', $status)];
      case '1':
      case '2':
      case '3':
      case '4':
        return ['code' => -1, 'msg' => '账号' . Constants::getByIndex('user_status', $status)];
      default:
        return ['code' => -1, 'msg' => '未定义状态'];
    }
  }

  public function checkLoginPassword($password, $password_hash) {
    if(!$this -> di -> getShared('security') -> checkHash($password, $password_hash)) {
      return ['code' => -1, 'msg' => '登陆密码错误'];
    }
    return ['code' => 0, 'msg' => '登陆密码正确'];
  }

  public function checkSafePassword($password, $password_hash) {
    if(!$this -> di -> getShared('security') -> checkHash($password, $password_hash)) {
      return ['code' => -1, 'msg' => '安全密码错误'];
    }
    return ['code' => 0, 'msg' => '安全密码正确'];
  }
}
